<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>消息推送表单</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body {
	height: 100%;
}

.fieldTitle {
	width: 80px !important;
}

.mini-tabs-leftButton, .mini-tabs-rightButton {
	display: none;
}

.mini-tabs-scrollCt {
	border-top: 0;
}

.mini-tabs-bodys {
	padding: 0;
}
.headerpan{
	margin-left: 10px;
	font-size: 14px;
	font-weight:bold;
}
</style>
<script type="text/javascript">
	var pushTypeData = [{'text':'即时推送','id':'0'},{'text':'指定时间','id':'1'}];
</script>
</head>
<body>
	<form id="dataForm">
		<div class="formContent">
			<input id="uuids" name="uuids" class="mini-hidden"
				style="width: 100%;" />
			<input id="type" name="type" class="mini-hidden"
				style="width: 100%;" value="自定义"/>
			<table class="formContentTable">
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
				<tr>
					<td class="fieldTitle">推送名称</td>
					<td class="fieldContent" colspan="3"><input id="msgName"
						required="true" name="msgName" class="mini-textbox"
						style="width: 100%;" value="${msgName}" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">接收人</td>
					<td class="fieldContent" colspan="3"><a
						href="javascript:addUsers()"><textarea id="users" name="users"
						style="width: 100%; height: 100px;" required="true" allowinput="false"
						class="mini-textarea" emptyText="无" value="${users}"></textarea></a></td>
				</tr>
				<tr>
					<td class="fieldTitle">推送方式</td>
					<td class="fieldContent"><input id="pushType" required="true"
						name="pushType" class="mini-combobox" style="width: 100%;"
						value="0" textField="text" valueField="id" data="pushTypeData"
						onvaluechanged="pushTypeChange" /></td>
					<td class="fieldTitle">推送时间</td>
					<td class="fieldContent"><input id="pushTime" name="pushTime"
						class="mini-datepicker" style="width: 100%;"
						onvaluechanged="checkPushTime" nullValue=""
						format="yyyy-MM-dd HH:mm:ss" timeFormat="HH:mm" showTime="true"
						showOkButton="true" showClearButton="false" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">推送信息</td>
					<td class="fieldContent" colspan="3"><textarea id="msgCon"
							name="msgCon" style="width: 100%; height: 150px;"
							required="true" class="mini-textarea" emptyText="无"
							value="${msgCon}"></textarea></td>
				</tr>
				<tr>
					<td class="fieldTitle">推送原因</td>
					<td class="fieldContent" colspan="3"><textarea id="pushReason"
							name="pushReason" style="width: 100%; height: 100px;"
							required="true" class="mini-textarea" emptyText="无"
							value="${pushReason}"></textarea></td>
				</tr>
				<tr>
					<td class="fieldTitle">编制人</td>
					<td class="fieldContent"><input id="creater" enabled="false"
						name="creater" class="mini-textbox" style="width: 100%;"
						value="${creater}" /></td>
					<td class="fieldTitle">编制日期</td>
					<td class="fieldContent"><input id="createTime" enabled="false"
						name="createTime" class="mini-datepicker" style="width: 100%;"
						value="${createTime}" /></td>
				</tr>
			</table>
		</div>
	</form>

	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var rootPath = parent.getRootPath();
		var userName = parent.getUserName();
		var action = parent.getAction();
		var uuid = parent.getUuid();
		var onlyCheck = parent.onlyCheck;
		
		var pushType = mini.get("pushType");
		var pushTime = mini.get("pushTime");
		
		var dataOri = null;
		
		var userData = null;
		var users = mini.get("users");
		var uuids = mini.get("uuids");

		var form = new mini.Form("dataForm");
		
		if(parent.hideAtt){
			parent.hideAtt();
		}
		/* 修改推送方式时 */
		function pushTypeChange(){
			var typeValue = pushType.getValue();
			if(typeValue == '0'){
				pushTime.setValue();
				pushTime.disable();
			}else{
				pushTime.enable();
			}
		}
		/* 修改推送方式时 */
		function checkPushTime(){
			var time = pushTime.getValue();
			var now = new Date();
			var needTime = now.setTime(now.getTime()+10*60*1000);
			if(time < needTime){
				top.commonTools.showTip("距离当前时间不得小于10分钟！", 2);
				pushTime.setValue(needTime);
			}
		}
		
		SetFormData();
		
		function SetFormData() {
			if(action == "new"){
				var o = new Object();
				o.creater = userName;
				o.pushType = '0';
				o.type = '自定义';
				o.createTime = new Date();
				form.setData(o);
				dataOri = o;
				pushTime.disable();
				return;
			}
			var messageid = mini.loading("获取中...", "Loading");
			var urlBase = '<c:url value="/msg/mng/form/"></c:url>'+ uuid;
			$.ajax({
				url : urlBase,
				type : "get",
				dataType : 'json',
				success : function(text) {
					if (!text) {
						return;
					}
					var o = mini.decode(text);
					var amount = o.Amount;
					if (typeof amount == "number") {
						o.Amount = amount.toFixed(2);
					}
					var tAmount = o.TotalAmount;
					if (typeof tAmount == "number") {
						o.TotalAmount = tAmount.toFixed(2);
					}
					var ratio = o.RetentionRatio;
					if (typeof ratio == "number") {
						o.RetentionRatio = ratio.toFixed(2);
					}
					var rAmount = o.RetentionAmount;
					if (typeof rAmount == "number") {
						o.RetentionAmount = rAmount.toFixed(2);
					}
					form.setData(o);
					dataOri = o;
					parent.labelModel(form);
				},
				complete : function(XMLHttpRequest, textStatus) {
					mini.hideMessageBox(messageid);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

				}
			});
		}
		function packData() {
			return form;
		}
		function addUsers(){
			if(action == "check" || onlyCheck){
				return;
			}else if(action == "edit"){
				top.commonTools.showTip("接收人不允许被修改！", 2);
				return;
			}
			mini.open({
				url : '<c:url value="/msg/mng/addUsers"></c:url>',
				title : "添加用户",
				width : 600,
				height : 400,
				ondestroy : function(action) {
					if(action == "ok"){
						userData = this.getIFrameEl().contentWindow.data;
						users.setValue(userData.names);
						uuids.setValue(userData.uuids);
						top.commonTools.showTip("添加接收人成功！", 1);
					}
				}
			});
		}

	</script>
</body>
</html>